package com.wfs.myapp.repository.bk;

import com.wfs.myapp.entity.domain.bk.BkGroup;
import com.wfs.myapp.entity.domain.bk.BkGroupMember;
import com.wfs.myapp.entity.vo.GroupListVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GroupMemberRepository extends JpaRepository<BkGroupMember, Long> {

    @Query(nativeQuery = true, value = " SELECT gm.id, gm.group_id, gm.user_id, gm.status, u.nickname, u.avatar " +
            " FROM bk_group_member gm LEFT JOIN user u ON gm.user_id = u.id " +
            " WHERE gm.group_id = ?1 " +
            " ORDER BY gm.created_time "
            )
    List<GroupListVo.GroupListMemberVo> findByGroupId(Long groupId);

    BkGroupMember findByGroupIdAndUserId(Long groupId, Long userId);

    @Query(nativeQuery = true, value = " SELECT gm.group_id FROM bk_group_member gm " +
            " WHERE gm.user_id = ?1 " +
            " GROUP BY gm.group_id "
    )
    List<Long> findGroupIdsByUserId(Long userId);

}




